//
//  MYGReportCell.swift
//  MYGrow
//
//  Created by 小火科技 on 2024/4/20.
//

import UIKit

class MYGReportCell: UITableViewCell {

    // MARK: - Property
    var model: MYGChatReportCellModel? {
        didSet {
            guard let model = model else {
                return
            }
            if model.is_agree == 0 {
                hintLabel.text = "申请消息已发送"
                editButton.isHidden = true
                return
            }
            
            //apply1=健康数据申请,apply2=生活习惯申请,apply3=健康史申请,apply4=病历夹申请,apply5=体检报告申请
            var str = ""
            switch model.type {
            case .apply1:
                str = "健康数据"
            case .apply2:
                str = "生活习惯"
            case .apply3:
                str = "健康史"
            case .apply4:
                str = "病历夹"
            case .apply5:
                str = "体检报告"
            default:
                str = "健康数据"
            }
            // 0 申请权限 1 同意 2 拒绝
            if model.is_agree == 1 {
                hintLabel.text = "您申请的查看\(str)数据用户已同意,"
                editButton.isHidden = false
            }else {
                hintLabel.text = "您申请的查看\(str)数据用户已拒绝"
                editButton.isHidden = true
            }
        
        }
    }
    
    var withDrawAction:((_ type:MYGIMMessageType)->Void)?
    // MARK: - init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        configUI()
        editButton.isHidden = true
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func configUI() {
        contentView.addSubview(stackView)
        stackView.addArrangedSubviews([hintLabel, editButton])
        stackView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(10)
            make.bottom.equalToSuperview().inset(0)
            make.centerX.equalToSuperview()
        }
    }
    // MARK: - lazy load
    private lazy var stackView: UIStackView = {
        let stackView = UIStackView()
        stackView.axis = .horizontal
        //stackView.spacing = 9
        stackView.alignment = .center
        return stackView
    }()
    
    private lazy var hintLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(104, 104, 104, 1)
        label.text = ""
        return label
    }()
    
    private lazy var editButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("这就去查看", for: .normal)
        btn.setTitleColor(.rgba(0, 77, 224, 1), for: .normal)
        btn.titleLabel?.font = .regular(12)
        btn.addTarget(self, action: #selector(withDraw), for: .touchUpInside)
        return btn
    }()
    
    
    @objc
    private func withDraw() {
        let type:MYGIMMessageType = self.model!.type
        withDrawAction?(type)
    }
}
